package com.rainbow.bam.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.rainbow.bam.entity.HtSource;
import com.rainbow.bam.entity.PaginationResponse;
import com.rainbow.bam.exception.BusinessCheckException;
import com.rainbow.bam.service.resource.HtSourceService;
import com.rainbow.bam.util.RequestHandler;

/**
 * 菜单管理控制类
 * 
 * @author zhaolei
 * @version $Id: HtSourceController.java, v 0.1 2015年11月19日 下午4:58:08 zhaolei Exp $
 */
@Controller
@RequestMapping("/source")
public class HtSourceController {

    @Autowired
    private HtSourceService htSourceService;

    /**
     * 菜单信息列表展现
     * 
     * @param request HttpServletRequest对象
     * @param response HttpServletResponse对象
     * @param model SpringFramework Model对象
     * @return 账户信息列表展现页面
     */
    @RequiresPermissions("source:query")
    @RequestMapping(value = "/sourcelist")
    public String accountList(HttpServletRequest request, HttpServletResponse response,
                              Model model) {
        PaginationResponse<HtSource> paginationResponse = htSourceService
            .findAccountsByPagination(RequestHandler.buildPaginationRequest(request, model));
        model.addAttribute("paginationResponse", paginationResponse);
        return "source/source_list";
    }

    /**
     * 新增菜单页面
     * 
     * @param request HttpServletRequest对象
     * @param response HttpServletResponse对象
     * @param model SpringFramework Model对象
     * @return 账户信息新增页面
     */
    @RequiresPermissions("source:add")
    @RequestMapping(value = "/add", method = RequestMethod.GET)
    public String addAccount(HttpServletRequest request, HttpServletResponse response,
                             Model model) {
        return "source/source_add";
    }

    /**
     * 新增菜单页面
     * 
     * @param request HttpServletRequest对象
     * @param response HttpServletResponse对象
     * @param model SpringFramework Model对象
     * @return 账户列表页面
     * @throws BusinessCheckException 
     */
    @RequiresPermissions("source:add")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public String addAccountHandler(HttpServletRequest request, HttpServletResponse response,
                                    Model model) throws BusinessCheckException {
        //        htDutyService.addAccount((HtAccount) RequestHandler.createBean(request,
        //            new HtAccount()));
        return "redirect:/source/sourcelist";
    }

    /**
     * 修改菜单页面
     * 
     * @param request HttpServletRequest对象
     * @param response HttpServletResponse对象
     * @param model SpringFramework Model对象
     * @param accountkey 账户编码
     * @return 账户信息修改页面
     */
    @RequiresPermissions("source:edit")
    @RequestMapping(value = "/edit/{sourceid}", method = RequestMethod.GET)
    public String editAccount(HttpServletRequest request, HttpServletResponse response, Model model,
                              @PathVariable("sourceid") Long sourceid) {
      //  HtSource htSource = this.htSourceService.findOne(sourceid);
        //model.addAttribute("htSource", htSource);
        return "source/source_edit";
    }

    /**
     * 删除菜单信息
     * 
     * @param request HttpServletRequest对象
     * @param response HttpServletResponse对象
     * @param model SpringFramework Model对象
     * @param accountkey 账户编码
     * @return 跳转回账户列表页面
     * @throws BusinessCheckException 
     */
    @RequiresPermissions("source:delete")
    @RequestMapping(value = "/delete/{sourceid}", method = RequestMethod.GET)
    public String deleteAccount(HttpServletRequest requet, HttpServletResponse response,
                                Model model,
                                @PathVariable("sourceid") Long sourceid) throws BusinessCheckException {
        // htDutyService.deleteAll(list);
        // htAccountServiceImpl.deleteAccount(accountkey);//删除账户
        return "redirect:/source/sourcelist";
    }

}
